<html>
<head><meta charset="utf-8"><title>AddressOf and stacked borrows · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf.20and.20stacked.20borrows.html">AddressOf and stacked borrows</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="160516765"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf%20and%20stacked%20borrows/near/160516765" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf.20and.20stacked.20borrows.html#160516765">(Mar 11 2019 at 20:49)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> I got MIRI's tests running on my branch for this and this case came up:</p>
<div class="codehilite"><pre><span></span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">12</span><span class="p">;</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="n">x</span><span class="p">;</span><span class="w"></span>

<span class="o">&amp;*</span><span class="n">x</span><span class="p">;</span><span class="w"> </span><span class="c1">// Stack is frozen</span>

<span class="kd">let</span><span class="w"> </span><span class="n">raw</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="o">*</span><span class="k">mut</span><span class="w"> </span><span class="kt">i32</span><span class="p">;</span><span class="w"> </span><span class="c1">// A - No longer creates a temporary `&amp;mut i32`</span>
<span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">*</span><span class="n">raw</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">42</span><span class="p">;</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</pre></div>


<p>Since the stack is frozen, <code>A</code> doesn't modify the stack, as such the last write isn't valid. Have you considered this already?</p>



<a name="160604928"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf%20and%20stacked%20borrows/near/160604928" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf.20and.20stacked.20borrows.html#160604928">(Mar 12 2019 at 20:03)</a>:</h4>
<p>reborrows like <code>&amp;mut *x</code> are accesses currently, even without the retagging</p>



<a name="160604940"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf%20and%20stacked%20borrows/near/160604940" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf.20and.20stacked.20borrows.html#160604940">(Mar 12 2019 at 20:03)</a>:</h4>
<p>so I guess we want something similar for reborrows-to-raw</p>



<a name="160605182"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf%20and%20stacked%20borrows/near/160605182" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf.20and.20stacked.20borrows.html#160605182">(Mar 12 2019 at 20:06)</a>:</h4>
<p>but, hm making them a write access is not nice... the entire point is that they can be dangling after all</p>



<a name="160605198"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf%20and%20stacked%20borrows/near/160605198" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf.20and.20stacked.20borrows.html#160605198">(Mar 12 2019 at 20:06)</a>:</h4>
<p>they certainly must unfreeze though, as your example shows</p>



<a name="160605314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf%20and%20stacked%20borrows/near/160605314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf.20and.20stacked.20borrows.html#160605314">(Mar 12 2019 at 20:08)</a>:</h4>
<p>maybe it should depend on the src ptr? like, when you come from a raw ptr to nothing, but when you come from a <code>Uniq</code> then pretend a write happened?</p>



<a name="160605512"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf%20and%20stacked%20borrows/near/160605512" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf.20and.20stacked.20borrows.html#160605512">(Mar 12 2019 at 20:10)</a>:</h4>
<p>so here's something interesting: I always said that <code>*mut</code> and <code>*const</code> are entirely identical. but then creating a <code>*const</code> would also hev to unfreeze. but the following is safe today:</p>
<div class="codehilite"><pre><span></span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">12</span><span class="p">;</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="n">x</span><span class="p">;</span><span class="w"></span>

<span class="kd">let</span><span class="w"> </span><span class="n">shr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;*</span><span class="n">x</span><span class="p">;</span><span class="w"> </span><span class="c1">// Stack is frozen</span>

<span class="kd">let</span><span class="w"> </span><span class="n">raw</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="o">*</span><span class="k">const</span><span class="w"> </span><span class="kt">i32</span><span class="p">;</span><span class="w"> </span><span class="c1">// Stack gets unfrozen?</span>

<span class="kd">let</span><span class="w"> </span><span class="n">_val</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">*</span><span class="n">shr</span><span class="p">;</span><span class="w"> </span><span class="c1">// but then this is UB</span>
</pre></div>



<a name="160605640"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf%20and%20stacked%20borrows/near/160605640" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf.20and.20stacked.20borrows.html#160605640">(Mar 12 2019 at 20:12)</a>:</h4>
<p>so seems loke the two raw ptr types are not identical after all? and creating a <code>*const</code> from an <code>&amp;mut</code> is more like turning it into a shared reference first? but that would make this UB:</p>
<div class="codehilite"><pre><span></span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">12</span><span class="p">;</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="n">x</span><span class="p">;</span><span class="w"></span>

<span class="o">&amp;*</span><span class="n">x</span><span class="p">;</span><span class="w"> </span><span class="c1">// Stack is frozen</span>
<span class="kd">let</span><span class="w"> </span><span class="n">raw</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="o">*</span><span class="k">const</span><span class="w"> </span><span class="kt">i32</span><span class="p">;</span><span class="w"> </span><span class="c1">// Stack remains frozen?</span>
<span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">*</span><span class="p">(</span><span class="n">raw</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="o">*</span><span class="k">mut</span><span class="w"> </span><span class="kt">i32</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="p">;</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</pre></div>



<a name="160605775"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf%20and%20stacked%20borrows/near/160605775" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf.20and.20stacked.20borrows.html#160605775">(Mar 12 2019 at 20:14)</a>:</h4>
<p>so it would matter if you turn an <code>&amp;mut</code> into a mutable or constant raw ptr</p>



<a name="160605828"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf%20and%20stacked%20borrows/near/160605828" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf.20and.20stacked.20borrows.html#160605828">(Mar 12 2019 at 20:15)</a>:</h4>
<p>I mean, it matters for the borrow checker, so maybe this makes sense. but I told people the oppose for so long^^<br>
<span class="user-mention" data-user-id="127859">@Taylor Cramer</span> you mentioned mutating through const raw ptrs is common in your codebase, how does that code usually look like?</p>



<a name="160608699"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf%20and%20stacked%20borrows/near/160608699" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf.20and.20stacked.20borrows.html#160608699">(Mar 12 2019 at 20:44)</a>:</h4>
<blockquote>
<p>mutating through const raw ptrs is common in your codebase</p>
</blockquote>
<p>sorry, I'm not sure what you're referring to</p>



<a name="160608840"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf%20and%20stacked%20borrows/near/160608840" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf.20and.20stacked.20borrows.html#160608840">(Mar 12 2019 at 20:46)</a>:</h4>
<p>I know there are lots of places that aren't careful about whether or not they use <code>*const</code> or <code>*mut</code></p>



<a name="160608861"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf%20and%20stacked%20borrows/near/160608861" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf.20and.20stacked.20borrows.html#160608861">(Mar 12 2019 at 20:46)</a>:</h4>
<p>but it's basically always in the context of FFI</p>



<a name="160644680"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf%20and%20stacked%20borrows/near/160644680" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf.20and.20stacked.20borrows.html#160644680">(Mar 13 2019 at 08:30)</a>:</h4>
<p><span class="user-mention" data-user-id="127859">@Taylor Cramer</span> are there places where you do <code>x as *const Foo</code> and then later mutate through that pointer? So it's less about the type on the FFI function but about the type at the cast -- but of course if this is a coercion, the cats type is informed by the function type.</p>



<a name="160798008"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf%20and%20stacked%20borrows/near/160798008" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf.20and.20stacked.20borrows.html#160798008">(Mar 14 2019 at 16:30)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> I'd imagine there are, yes</p>



<a name="160798049"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf%20and%20stacked%20borrows/near/160798049" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf.20and.20stacked.20borrows.html#160798049">(Mar 14 2019 at 16:31)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> I don't think it'd be unreasonable to ask for those to be changed, but historically I'd always thought that *const and *mut were "just a lint"</p>



<a name="160798451"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf%20and%20stacked%20borrows/near/160798451" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf.20and.20stacked.20borrows.html#160798451">(Mar 14 2019 at 16:36)</a>:</h4>
<blockquote>
<p>historically I'd always thought that *const and *mut were "just a lint"</p>
</blockquote>
<p>same here</p>



<a name="160798458"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf%20and%20stacked%20borrows/near/160798458" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf.20and.20stacked.20borrows.html#160798458">(Mar 14 2019 at 16:36)</a>:</h4>
<p>but also I dont see another way to handle <span class="user-mention" data-user-id="116118">@Matthew Jasper</span>'s example</p>



<a name="160798482"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf%20and%20stacked%20borrows/near/160798482" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf.20and.20stacked.20borrows.html#160798482">(Mar 14 2019 at 16:36)</a>:</h4>
<p>and also I did not know that the borrow checker treats them differently</p>



<a name="160798511"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf%20and%20stacked%20borrows/near/160798511" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf.20and.20stacked.20borrows.html#160798511">(Mar 14 2019 at 16:37)</a>:</h4>
<p><code>x as *const T</code> is borrow-checked like <code>&amp;*x</code> and hence allows outstanding shared loans</p>



<a name="160799440"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf%20and%20stacked%20borrows/near/160799440" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf.20and.20stacked.20borrows.html#160799440">(Mar 14 2019 at 16:47)</a>:</h4>
<p>Well, it can be modelled with some of the ideas for 2 phase borrows. <span aria-label="grinning face with smiling eyes" class="emoji emoji-1f601" role="img" title="grinning face with smiling eyes">:grinning_face_with_smiling_eyes:</span></p>



<a name="160799572"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf%20and%20stacked%20borrows/near/160799572" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf.20and.20stacked.20borrows.html#160799572">(Mar 14 2019 at 16:48)</a>:</h4>
<p>uh... you want raw borrows to be two-phase?</p>



<a name="163720576"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf%20and%20stacked%20borrows/near/163720576" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf.20and.20stacked.20borrows.html#163720576">(Apr 19 2019 at 07:56)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> I've tried the new version of stacked borrows on the AddressOf branch and ran into the following issue:</p>
<div class="codehilite"><pre><span></span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">m</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="n">raw</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">x</span><span class="p">;</span><span class="w"> </span><span class="c1">// The branch is still using the adjusted type, rather than syntax, but you get the idea</span>
<span class="kd">let</span><span class="w"> </span><span class="n">c</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="n">raw</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">x</span><span class="p">;</span><span class="w"></span>
</pre></div>


<p>The stack after each line is <code>[U]</code>, <code>[U, SRW]</code>, <code>[U, SRO, SRW]</code> -&gt; bug. It's not entirely clear to me what the correct thing to do here is. Currently <code>&amp;x as *const _</code> invalidates the mutable pointer, but that doesn't really seem desirable.</p>



<a name="163730192"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf%20and%20stacked%20borrows/near/163730192" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf.20and.20stacked.20borrows.html#163730192">(Apr 19 2019 at 11:49)</a>:</h4>
<p>I think the fix is to never make <code>SRO</code> borrows "weak"</p>



<a name="163730195"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf%20and%20stacked%20borrows/near/163730195" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf.20and.20stacked.20borrows.html#163730195">(Apr 19 2019 at 11:49)</a>:</h4>
<p>that just doesn't work very well</p>



<a name="164560671"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf%20and%20stacked%20borrows/near/164560671" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf.20and.20stacked.20borrows.html#164560671">(Apr 30 2019 at 18:03)</a>:</h4>
<p><span class="user-mention" data-user-id="116118">@Matthew Jasper</span> <a href="https://github.com/rust-lang/miri/pull/718" target="_blank" title="https://github.com/rust-lang/miri/pull/718">https://github.com/rust-lang/miri/pull/718</a> should help with this.</p>



<a name="164566991"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf%20and%20stacked%20borrows/near/164566991" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/AddressOf.20and.20stacked.20borrows.html#164566991">(Apr 30 2019 at 19:14)</a>:</h4>
<p>Also, the blog post about the new Stacked Borrows is finally done: <a href="https://internals.rust-lang.org/t/stacked-borrows-2/9951" target="_blank" title="https://internals.rust-lang.org/t/stacked-borrows-2/9951">https://internals.rust-lang.org/t/stacked-borrows-2/9951</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>